<template>
  <view>
    
    <view class="search-box">
      <search @click="gosearch"></search>
    </view>
    
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
      <!-- previous-margin="15rpx" next-margin="15rpx" -->
      <swiper-item v-for="(item,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>

    <view class="nav-list">
      <view class="nav-item" v-for="(item, i) in navList" :key="i" @click="navClickHandler(item)">
        <image :src="item.image_src" class="nav-img"></image>
      </view>
    </view>
    
   <view class="recomd">
      <view class="recomd-one" v-for="(item, i) in recomList" :key="i">
        <view class="text-titl">
          {{item.name}}
        </view>
        <image :src="item.img_src" class="reimg"></image>
      </view>
    </view>

    <!-- <view class="floor-list">
      <view class="floor-item" v-for="(item, i) in floorList" :key="i">
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        
        <view class="floor-img-box">
          
          <navigator class="left-img-box" :url='item.product_list[0].url'>
            <image :src="item.product_list[0].image_src" :style="{width:
              item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
          </navigator>
          
          <view class="right-img-box">
            <navigator class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 !== 0" :url="item2.url">
              <image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width + 'rpx'}"></image>
            </navigator>
          </view>
        </view>
      </view>
    </view> -->
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  export default {
    mixins: [badgeMix],
    data() {
      return {
        swiperList: [],
        navList: [],
        floorList: [],
        recomList: [
              {
                name: '甄选推荐',
                img_src: "../../static/recomd/01.jpg"
              },
              {
                name: '猜你喜欢',
                img_src: "../../static/recomd/02.jpg"
              },
              {
                name: '精选爆款',
                img_src: "../../static/recomd/03.jpg"
              },
              {
                name: '限时秒杀',
                img_src: "../../static/recomd/04.jpg"
              }
        ]
      };
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getfloorList()
    },
    methods: {
      // 3. 获取轮播图数据的方法
      async getSwiperList() {
        // 3.1 发起请求
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        // 3.2 请求失败
        if (res.meta.status !== 200) {
          return uni.$showMsg()
        }
        // 3.3 请求成功，为 data 中的数据赋值
        this.swiperList = res.message
        uni.$showMsg('数据请求成功')
      },
      async getNavList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navList = res.message
      },
      navClickHandler(item) {
        if (item.name == '分类') {
          uni.switchTab({
            url: '/pages/cate/cate'
          })
        }
      },
      async getfloorList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) return uni.$showMsg()
        
        res.message.forEach(floor => {
          floor.product_list.forEach(prod => {
            prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
          })
        })
        this.floorList = res.message
      },
      gosearch() {
        uni.navigateTo({
          url: '/subpkg/ssearch/ssearch'
      })
    }
  },
}
</script>

<style lang="scss">
  page {
    background-color: #fff;
  }
  swiper {
    width: 94%;
    height: 330rpx;
    display: flex;
    border-radius: 25px;
    margin: 20rpx auto;
    justify-content: center;
  }

  swiper-item {
    width: 705rpx;
    border-radius: 25px;
  }

  .swiper-item,
  .swiper-item image {
    width: 100%;
    height: 100%;
    // margin: 0 6px;
    border-radius: 25px;
  }

  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;

    .nav-img {
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-title {
    height: 60rpx;
    width: 100%;
    display: flex;
  }
  
  .right-img-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  }
  .floor-img-box {
  display: flex;
  justify-content: center;
  padding-left: 10rpx;
  }
  
  .search-box {
    position: sticky;
    top: 0;
    z-index: 999;
  }
  
  .reimg {
    width: 700rpx;
    height: 700rpx;
    margin-top: 20px;
    border-radius: 40px;
    box-shadow: 0 0 20px #8d8d8d;
  }
  .recomd {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background-color: #fff;
    border-radius: 40rpx;
  }
  .recomd-one {
    margin: 0 auto;
    margin-top: 30px;
    border-radius: 40rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    
  }
  .text-titl {
    margin: 0 auto;
    font-size: 18px;
   
  }
</style>
